public class LargestPalindromic {
    // leetcode 最大回文数字
    // https://leetcode.cn/problems/largest-palindromic-number/description/
    public String largestPalindromic(String num) {
        long[] hash = new long[10];
        for (char c : num.toCharArray()) {
            hash[c-'0']++;
        }
        StringBuilder sb = new StringBuilder();
        int index = -1;
        for (int i = 0; i <= 9; i++) {
            if (hash[i] != 0) {
                while (hash[i]/2 != 0) {
                    sb.append(i);
                    sb.insert(0, i);
                    hash[i] -= 2;
                }
                if (hash[i] != 0) index = i;
            }
        }
        if (index != -1) {
            sb.insert(sb.length()/2, index);
        }
        while (sb.length() >= 2 && sb.charAt(0) == '0') {
            sb.deleteCharAt(0);
            sb.deleteCharAt(sb.length() - 1);
        }
        return sb.length() == 0 ? "0" : sb.toString();
    }

    public static void main(String[] args) {
//        LargestPalindromic l = new LargestPalindromic();
//        System.out.println(l.largestPalindromic("444947137"));

        Integer a = 100;
        Integer b = 100;
        System.out.println(a==b);
    }
}
